package lesson.score;

import lesson.base.BaseServlet;
import lesson.permission.Role;
import lesson.user.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;
import java.util.List;

@WebServlet("/score/*")
@Role(User.ROLE_ADMIN)
public class ScoreServlet extends BaseServlet {

    private ScoreService scoreService = new ScoreService();


    public void save(List<Score> scores) throws ServletException, IOException {
        String msg = scoreService.save(scores);
        writeJSON(msg == null, msg);
    }


    public void list(Integer examId, Integer classId) throws ServletException, IOException {
        writeJSON(true, null, scoreService.listStudentScores(examId, classId));
    }


    public void listGradeStatisticsData(Integer examId, Integer gradeId, Integer subjectId) throws ServletException, IOException {
        writeJSON(true, null, scoreService.listGradeStatisticsData(examId, gradeId, subjectId));
    }

    public void listClassStatisticsData(Integer classId, Integer subjectId) throws ServletException, IOException {
        writeJSON(true, null, scoreService.listClassStatisticsData(classId, subjectId));
    }
}
